package com.gc.business.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gc.common.utils.StringUtils;
import org.springframework.stereotype.Service;
import com.gc.business.mapper.UserSignMapper;
import com.gc.business.domain.UserSign;
import com.gc.business.service.IUserSignService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;

/**
 * 人员签到 服务层实现
 * 
 * @author hruiyan
 * @date 2020-11-25
 */
@Slf4j
@Service
public class UserSignServiceImpl extends ServiceImpl<UserSignMapper, UserSign> implements IUserSignService {

    @Override
    public List<UserSign> list(UserSign userSign){
        LambdaQueryWrapper<UserSign> wrapper = new LambdaQueryWrapper<>();
        if(userSign != null){
            if(StringUtils.isNotEmpty(userSign.getSignId())){
                wrapper.eq(UserSign::getSignId, userSign.getSignId());
            }
            if(StringUtils.isNotEmpty(userSign.getUserId())){
                wrapper.eq(UserSign::getUserId, userSign.getUserId());
            }
            if(StringUtils.isNotEmpty(userSign.getLongitude())){
                wrapper.eq(UserSign::getLongitude, userSign.getLongitude());
            }
            if(StringUtils.isNotEmpty(userSign.getLatitude())){
                wrapper.eq(UserSign::getLatitude, userSign.getLatitude());
            }
            if(StringUtils.isNotEmpty(userSign.getAddressDetails())){
                wrapper.like(UserSign::getAddressDetails, userSign.getAddressDetails());
            }
            if(StringUtils.isNotEmpty(userSign.getCreateBy())){
                wrapper.eq(UserSign::getCreateBy, userSign.getCreateBy());
            }
            if(StringUtils.isNotEmpty(userSign.getCreateTime())){
                //wrapper.eq(UserSign::getCreateTime, userSign.getCreateTime());
                wrapper.apply("date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')",userSign.getCreateTime());
                wrapper.apply("date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')",userSign.getCreateTime());
            }
            if(StringUtils.isNotEmpty(userSign.getUpdateBy())){
                wrapper.eq(UserSign::getUpdateBy, userSign.getUpdateBy());
            }
            if(StringUtils.isNotEmpty(userSign.getUpdateTime())){
                wrapper.eq(UserSign::getUpdateTime, userSign.getUpdateTime());
            }
            if(StringUtils.isNotEmpty(userSign.getRemark())){
                wrapper.eq(UserSign::getRemark, userSign.getRemark());
            }
        }
        return baseMapper.selectList(wrapper);
    }
}
